$(function () {
	$("input.date").datetimepicker({
		format: 'yyyy-mm-dd',
		minView: 2,
		autoclose: true,
		language: "zh-CN"
	});

	// 分页参数条件
	function queryParams() {
		var param = {
			className: $("#className").val(),
			productId: $("#productId").val(),
			pageNum: this.pageNumber,
			pageSize: this.pageSize
		}
		return param;
	}

	// 响应消息处理
	function responseHandler(res) {
		if (res) {
			return {
				"rows": res.rows,
				"total": res.total
			};
		} else {
			return {
				"rows": [],
				"total": 0
			};
		}
	}

	function operateFormatter(value, row, index) {
		return [
			'<a class="select" href="javascript:void(0)" title="选择">',
			'<i class="glyphicon glyphicon-check">选择</i>',
			'</a>  '
		].join('');
	}

	var operateEvents = {
		'click .select': function (e, value, row, index) {
			$("input[name='student.classes.name']").val(row.name);
			$("#classSelect").modal("hide");
		}
	};

	$("#classForm").bootstrapTable({
		method: 'GET',
		dataType: 'json',
		contentType: "application/json",
		cache: false,
		striped: true,					// 是否显示行间隔色
		sidePagination: "server",		// 服务端分页
		url: "class/lists",
		pagination: true,
		queryParams: queryParams,
		pageNumber: 1,					// 初始化加载第一页，默认第一页
		pageSize: 10,					// 每页的记录行数（*）
		pageList: [10, 25, 50, 100],	// 可供选择的每页的行数（*）
		showExport: false,
		responseHandler: responseHandler,
		columns: [
			{
				field: "name",
				title: "班级名称",
				align: "center",
				valign: "middle"
			},
			{
				field: "remarks",
				title: "班级备注",
				align: "center",
				valign: "middle"
			},
			{
				title: "操作",
				align: "center",
				valign: "middle",
				events: operateEvents,
				formatter: operateFormatter
			}
		]
	});

	$("button.selectClass").click(function () {
		$("#classForm").bootstrapTable("refresh");
	});

	$('div[type="info"]').click(function () {
		$(this).siblings('div').show();
		$(this).siblings('div').animate({
			opacity: 1
		}, 300, function () {
			$(this).show();
		});
	});

	$('.modal-mask').click(function () {
		$(this).animate({
			opacity: 0
		}, 300, function () {
			$(this).hide();
		});
	});

	$('span.input-group-btn').click(function () {
		$(this).siblings('input').val('');
	});

	$("button[data-type='export']").click(function () {
		var action = $("form.form-inline").attr("action");
		$("form.form-inline").attr("action", "attendance/export");
		$("form.form-inline").submit();
		$("form.form-inline").attr("action", action);
	});

	$('button[type="submit"]').click(function () {
		$.showloading();
	});
});